# -*- coding:utf-8 -*-
# @FileName  :user.py
# @Time      :2020/10/25 14:59
# @Author    :zhoujirong
from common.http_request import Request
from biz.support.urls import ServerUrl

class UserRequest:

    @classmethod
    def login(cls,username,password,phonecode,captcha,mode,needPWD):
        '''
        调用登录接口的
        :param username: 用户名
        :param password: 密码
        :return:
        '''
        data = {
            'username':username,
            'password':password,
            'phonecode':phonecode,
            'captcha':captcha,
            'mode':mode,
            'needPWD':needPWD
        }
        req = Request(ServerUrl.login_url,data=data)
        return req.post()

    @classmethod
    def login_cookie(cls,username,password,phonecode,captcha,mode,needPWD):
        '''
        调用登录接口的
        :param username: 用户名
        :param password: 密码
        :return:
        '''
        data = {
            'username':username,
            'password':password,
            'phonecode':phonecode,
            'captcha':captcha,
            'mode':mode,
            'needPWD':needPWD
        }
        req = Request(ServerUrl.login_url,data=data)
        return req.post_cookie()

    @classmethod
    def create(cls,userName,
                    nickName,
                    idCard,
                    orgId,
                    userType,
                    telephone,
                    mobile,
                    weiChat,
                    userEmail,
                    orgPhone,
                    postCode,
                    address,
                    deptName,
                    ipbindflag,
                    ipbindnum,
                    macbindflag,
                    macbindnum,
                    mark,
                    lockFlag,
                    resetFlag,
                    stopFlag,
                    roleIds,
                    assignRoleIds,cookie):
        '''新建用户'''
        data = {
        'userName':userName,
        'nickName':nickName,
        'idCard':idCard,
        'orgId':orgId,
        'userType':userType,
        'telephone':telephone,
        'mobile':mobile,
        'weiChat':weiChat,
        'userEmail':userEmail,
        'orgPhone':orgPhone,
        'postCode':postCode,
        'address':address,
        'deptName':deptName,
        'ipbindflag':ipbindflag,
        'ipbindnum':ipbindnum,
        'macbindflag':macbindflag,
        'macbindnum':macbindnum,
        'mark':mark,
        'lockFlag':lockFlag,
        'resetFlag':resetFlag,
        'stopFlag':stopFlag,
        'roleIds':roleIds,
        'assignRoleIds':assignRoleIds
        }
        req = Request(ServerUrl.user_create_url,data=data,headers=cookie)
        return req.post()

    @classmethod
    def per_userattr(cls,userName,
            printPermit,
            printAmount,
            savePermit,
            creditUser,
            interfaceCreditUser,
            whiteList,cookie):
        '''个人权限菜单添加'''
        data ={
            'userName':userName,
            'printPermit':printPermit,
            'printAmount':printAmount,
            'savePermit':savePermit,
            'creditUser':creditUser,
            'interfaceCreditUser':interfaceCreditUser,
            'whiteList':whiteList
        }
        req = Request(ServerUrl.user_per_userattr_url,data=data,headers=cookie)
        return req.post()

    @classmethod
    def ent_userattr(cls, userName,
                     printPermit,
                     printAmount,
                     savePermit,
                     creditUser,
                     interfaceCreditUser,
                     whiteList, cookie):
        '''企业权限菜单添加'''
        data = {
            'userName': userName,
            'printPermit': printPermit,
            'printAmount': printAmount,
            'savePermit': savePermit,
            'creditUser': creditUser,
            'interfaceCreditUser': interfaceCreditUser,
            'whiteList': whiteList
        }
        req = Request(ServerUrl.user_ent_userattr_url, data=data, headers=cookie)
        return req.post()

    @classmethod
    def changepasswordfirst(cls,cookie):
        req = Request(ServerUrl.user_changepasswordfirst_url,headers=cookie)
        return req.get()

    @classmethod
    def changepassword(cls,cookie):
        req = Request(ServerUrl.user_changepassword_url, headers=cookie)
        return req.get()

    @classmethod
    def changepasswordusername(cls, cookie):
        req = Request(ServerUrl.user_changepasswordusername_url, headers=cookie)
        return req.get()

    @classmethod
    def updatepasswd(cls,password,
                newpassword,
                new,cookie):
        '''修改密码'''
        data = {
                'password':password,
                'newpassword':newpassword,
                'new':new
        }
        req = Request(ServerUrl.user_update_password_url,data=data,headers=cookie)
        return req.post()

    @classmethod
    def user_update(cls,assignRoleIds,address,
                        createNickname,
                        createTime,
                        createUsername,
                        deptId,
                        deptName,
                        desc1,
                        desc2,
                        desc3,
                        desc4,
                        desc5,
                        desc6,
                        ext1,
                        ext10,
                        ext11,
                        ext12,
                        ext13,
                        ext14,
                        ext15,
                        ext16,
                        ext17,
                        ext18,
                        ext19,
                        ext2,
                        ext20,
                        ext21,
                        ext22,
                        ext23,
                        ext24,
                        ext25,
                        ext26,
                        ext27,
                        ext28,
                        ext29,
                        ext3,
                        ext30,
                        ext4,
                        ext5,
                        ext6,
                        ext7,
                        ext8,
                        ext9,
                        id,
                        idCard,
                        ipbindflag,
                        ipbindnum,
                        lockFlag,
                        macbindflag,
                        macbindnum,
                        mark,
                        mobile,
                        nickName,
                        orgId,
                        orgPhone,
                        password,
                        plainPassword,
                        postCode,
                        pwdUpdateTime,
                        resetFlag,
                        roleName,
                        salt,
                        shortcutFlag,
                        stopFlag,
                        stopReason,
                        stopTime,
                        telephone,
                        updateNickname,
                        updateTime,
                        updateUsername,
                        userEmail,
                        userName,
                        userType,
                        weiChat,
                        orgTree,
                        roleIds,cookie):
        '''用户编辑'''
        data = {
        'assignRoleIds':assignRoleIds,
        'address':address,
        'createNickname':createNickname,
        'createTime':createTime,
        'createUsername': createUsername,
        'deptId':deptId,
        'deptName':deptName,
        'desc1':desc1,
        'desc2':desc2,
        'desc3':desc3,
        'desc4':desc4,
        'desc5':desc5,
        'desc6':desc6,
        'ext1':ext1,
        'ext10':ext10,
        'ext11':ext11,
        'ext12':ext12,
        'ext13':ext13,
        'ext14':ext14,
        'ext15':ext15,
        'ext16':ext16,
        'ext17':ext17,
        'ext18':ext18,
        'ext19':ext19,
        'ext2':ext2,
        'ext20':ext20,
        'ext21':ext21,
        'ext22':ext22,
        'ext23':ext23,
        'ext24':ext24,
        'ext25':ext25,
        'ext26':ext26,
        'ext27':ext27,
        'ext28':ext28,
        'ext29':ext29,
        'ext3':ext3,
        'ext30':ext30,
        'ext4':ext4,
        'ext5':ext5,
        'ext6':ext6,
        'ext7':ext7,
        'ext8':ext8,
        'ext9':ext9,
        'id':id,
        'idCard':idCard,
        'ipbindflag':ipbindflag,
        'ipbindnum':ipbindnum,
        'lockFlag':lockFlag,
        'macbindflag':macbindflag,
        'macbindnum':macbindnum,
        'mark':mark,
        'mobile':mobile,
        'nickName':nickName,
        'orgId':orgId,
        'orgPhone':orgPhone,
        'password':password,
        'plainPassword':plainPassword,
        'postCode':postCode,
        'pwdUpdateTime':pwdUpdateTime,
        'resetFlag':resetFlag,
        'roleName':roleName,
        'salt':salt,
        'shortcutFlag':shortcutFlag,
        'stopFlag':stopFlag,
        'stopReason':stopReason,
        'stopTime':stopTime,
        'telephone':telephone,
        'updateNickname':updateNickname,
        'updateTime':updateTime,
        'updateUsername':updateUsername,
        'userEmail':userEmail,
        'userName':userName,
        'userType':userType,
        'weiChat':weiChat,
        'orgTree':orgTree,
        'roleIds':roleIds
        }
        req = Request(ServerUrl.user_update_url,data=data,headers=cookie)
        return req.post()

    @classmethod
    def per_attr_update(cls,createDate,
                            createUser,
                            creditUser,
                            ext1,
                            ext2,
                            ext3,
                            ext4,
                            ext5,
                            ext6,
                            id,
                            interfaceCreditUser,
                            lockStat,
                            printAmount,
                            printPermit,
                            resCode,
                            resMsg,
                            savePermit,
                            serialNumber,
                            updateDate,
                            userName,
                            whiteList,cookie):
        '''个人标签页信息编辑'''
        data = {
        'createDate':createDate,
        'createUser':createUser,
        'creditUser':creditUser,
        'ext1':ext1,
        'ext2':ext2,
        'ext3':ext3,
        'ext4':ext4,
        'ext5':ext5,
        'ext6':ext6,
        'id':id,
        'interfaceCreditUser':interfaceCreditUser,
        'lockStat':lockStat,
        'printAmount':printAmount,
        'printPermit':printPermit,
        'resCode':resCode,
        'resMsg':resMsg,
        'savePermit':savePermit,
        'serialNumber':serialNumber,
        'updateDate':updateDate,
        'userName':userName,
        'whiteList':whiteList
        }
        req = Request(ServerUrl.user_perattr_update_url,data=data,headers=cookie)
        return req.post()

    @classmethod
    def ent_attr_update(cls, amountLimit,
                            amountQuery,
                            bindNumber,
                            bindPermit,
                            createDate,
                            createUser,
                            creditUser,
                            downloadPermit,
                            ext1,
                            ext2,
                            ext3,
                            ext4,
                            ext5,
                            ext6,
                            id,
                            interfaceCreditUser,
                            lockStat,
                            printAmount,
                            printPermit,
                            resCode,
                            resMsg,
                            savePermit,
                            serialNumber,
                            timeLimit,
                            updateDate,
                            userName,
                            whiteList,
                            workTime, cookie):
        '''企业标签页信息编辑'''
        data = {
            'amountLimit':amountLimit,
            'amountQuery':amountQuery,
            'bindNumber':bindNumber,
            'bindPermit':bindPermit,
            'createDate':createDate,
            'createUser':createUser,
            'creditUser':creditUser,
            'downloadPermit':downloadPermit,
            'ext1':ext1,
            'ext2':ext2,
            'ext3':ext3,
            'ext4':ext4,
            'ext5':ext5,
            'ext6':ext6,
            'id':id,
            'interfaceCreditUser':interfaceCreditUser,
            'lockStat':lockStat,
            'printAmount':printAmount,
            'printPermit':printPermit,
            'resCode':resCode,
            'resMsg':resMsg,
            'savePermit':savePermit,
            'serialNumber':serialNumber,
            'timeLimit':timeLimit,
            'updateDate':updateDate,
            'userName':userName,
            'whiteList':whiteList,
            'workTime':workTime
        }
        req = Request(ServerUrl.user_entattr_update_url, data=data, headers=cookie)
        return req.post()

    @classmethod
    def get_page(cls,curPage,
            maxSize,
            search_LIKE_userName,
            search_LIKE_nickName,
            search_IN_orgId,
            search_IN_userType,
            search_EQ_stopFlag,
            search_EQ_lockFlag,cookie):
        '''用户检索'''
        params = {
            'curPage':curPage,
            'maxSize':maxSize,
            'search_LIKE_userName':search_LIKE_userName,
            'search_LIKE_nickName':search_LIKE_nickName,
            'search_IN_orgId':search_IN_orgId,
            'search_IN_userType':search_IN_userType,
            'search_EQ_stopFlag':search_EQ_stopFlag,
            'search_EQ_lockFlag':search_EQ_lockFlag
        }
        req = Request(ServerUrl.user_get_page_url,params=params,headers=cookie)
        return req.get()

    @classmethod
    def del_user(cls,ids,cookie):
        '''用户删除'''
        params = {
            'ids':ids
        }
        req = Request(ServerUrl.user_del_url,params=params,headers=cookie)
        return req.post()





if __name__ == "__main__":
    result = UserRequest.login_cookie('zjr','39493066c362631d25cca1988893c319','','','PASSWORDNOCAPTCHA','true')
    print(result)
